# 实现部门增删改查接口封装
import requests


from common.get_token import grt_login_token

class IhrmDepApi:

    # 添加部门
    @classmethod
    def add_dep(cls, token, data):
        resp = requests.post('http://ihrm-test.itheima.net/api/company/department', headers={"Authorization": token},
                             json=data)
        return resp


        # 修改部门
    @classmethod
    def modify_dep(cls, token, emp_id,data):
        resp = requests.put('http://ihrm-test.itheima.net/api/company/department/' + emp_id, headers={"Authorization": token},
                            json=data)
        return resp

        # 查询部门
    @classmethod
    def query_dep(cls, token, emp_id):
        resp = requests.get('http://ihrm-test.itheima.net/api/company/department/' + emp_id, headers={"Authorization": token})
        return resp

        # 删除部门
    @classmethod
    def delete_dep(cls, token, emp_id):
        resp = requests.delete('http://ihrm-test.itheima.net/api/company/department/' + emp_id, headers={"Authorization": token})
        return resp


if __name__ == '__main__':
    token=grt_login_token()
    id = '1524722556689534976'
    rsep=IhrmDepApi.add_dep(token,{"name": "杀猪部", "code": "666888"})
    print('添加部门',rsep.json())
    # rsep=IhrmDepApi.query_dep(token,id)
    # print('查询部门',rsep.json())
    # rsep=IhrmDepApi.modify_dep(token,id,{"name": "卖猪部", "code": "6668888"})
    # print('修改部门',rsep.json())
    # rsep=IhrmDepApi.delete_dep(token,id)
    # print('删除部门',rsep.json())